package com.workcell.workdata.xthings.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.workcell.workdata.xthings.entity.BindType;
import com.workcell.workdata.xthings.mapper.BindTypeMapper;
import com.workcell.workdata.xthings.service.BindTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Admin
 * @description 针对表【t_bind_type(设备类型绑定表)】的数据库操作Service实现
 * @createDate 2023-04-04 10:16:13
 */
@Service
@RequiredArgsConstructor
public class BindTypeServiceImpl extends ServiceImpl<BindTypeMapper, BindType> implements BindTypeService {
    private final BindTypeMapper bindTypeMapper;

    /**
     * 根据主设备类型，查询其可绑定的设备列表
     *
     * @param masterType 主设备类型
     * @return 主设备类型可绑定设备类型
     */
    @Override
    public List<BindType> slaverTypesByMasterType(String masterType) {
        LambdaQueryWrapper<BindType> lambdaQueryWrapper = Wrappers.lambdaQuery(BindType.class)
                .eq(BindType::getMasterType, masterType);
        return bindTypeMapper.selectList(lambdaQueryWrapper);
    }

    /**
     * 检查两个设备是否能绑定
     * @param masterType 主设备类型
     * @param slaverType 从设备类型
     * @return 布尔值
     */
    @Override
    public boolean checkBind(String masterType, String slaverType) {
        LambdaQueryWrapper<BindType> lambdaQueryWrapper = Wrappers.lambdaQuery(BindType.class)
                .eq(BindType::getMasterType, masterType)
                .eq(BindType::getSlaveType, slaverType);
        Long selectCount = bindTypeMapper.selectCount(lambdaQueryWrapper);
        return selectCount > 0;
    }
}




